﻿#pragma once
#include "ZLabel.h"
#include "ZCaret.h"
#include "ZTextDocument.h"

namespace ZuiLib
{

class ZTextInput:public ZLabel
{
public:
	ZUI_CLASS_NAME("zui.TextInput");
	ZTextInput(void);
	~ZTextInput(void);

	const char* GetClass() const ZOVERRIDE;
	void* GetInterface(const char* pstrName) ZOVERRIDE;

	void DoEvent(TEventUI& event) ZOVERRIDE;
	void PaintText(ZRenderer* hDC) ZOVERRIDE;
	void SetPos(RECT rc) ZOVERRIDE;
	void SetAttribute(const char* pstrName, const char* pstrValue) ZOVERRIDE;

	void UpdateScroll();//更新光标
	void UpdateText();

	int CharFromPos(POINT pt);
	POINT PosFromChar(int nCh);

	ZString GetText() const ZOVERRIDE;
	void SetText(const char* pstrText) ZOVERRIDE;

	void SetTipText(const char* tipText);

	void SetReadOnly(bool readonly);

	void Copy();
	void Cut();
	void Paste();
	void SelAll();
	void SelNone();
	void Undo();
//signal:
	sigslot::signal1<ZTextInput*> SignalTextChanged;
	sigslot::signal1<ZTextInput*> SignalReturn;
	sigslot::signal1<ZTextInput*> SignalEscape;
	sigslot::signal2<ZTextInput*,bool> SignalUpDown;
private:
	DISALLOW_COPY_AND_ASSIGN(ZTextInput);

	int GetScrollMax();
	RECT GetCaretRect();
	void SetCaretPos(POINT pt);//设置光标位置

	void RemoveSel();
	void RemoveEditing();

	void PaintTextBk(ZRenderer* render);
	void PaintTextEditing(ZRenderer* render);

	uint32_t m_uButtonState;
	ZCaretPtr m_caret;
	ZTextDocument  m_doc;
	
	ZString m_tipText;

	//正在编辑的文字
	int m_editingBegin;
	int m_editingEnd;
	int m_editingOffset;

	int m_selBegin;
	int m_selEnd;
	int m_scroll;
	int m_caretPos;
	bool m_needResetText;
	bool m_readOnly;
	bool m_password;
	ZWChar m_passwordChar;
};





}